package com.afkt.project.ui.slice;


import com.afkt.project.model.bean.MyListBean;
import com.afkt.project.ui.adapter.MyListAdapter;
import com.dev.utils.LogUtils;
import com.ohos.afkt.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.ListContainer;
import ohos.agp.window.dialog.ToastDialog;
import ohos.app.Environment;

import java.util.ArrayList;
import java.util.List;

public class PathInformationSlice extends AbilitySlice {

    private ListContainer listContainer;
    private MyListAdapter mAdapter;
    private Button goBack;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_layout_pathInformation);


        /**
         *设置返回
         * */
        goBack =(Button) findComponentById(ResourceTable.Id_btn_crash_back);
        if(goBack!=null){
            goBack.setClickedListener(component -> {
               onBackground();
            });
        }

        initList();
    }

    private void initList() {
        List<MyListBean> list = initData();
        listContainer = (ListContainer) findComponentById(ResourceTable.Id_ringtone_list);
        mAdapter = new MyListAdapter(list, this);
        listContainer.setItemProvider(mAdapter);
        listContainer.setItemClickedListener((listContainer, component, position, l) -> {
            switch (position) {
                //内部存储路径
                case 0:
                    new ToastDialog(getContext()).setText("已输出到HiLog上").show();
                    LogUtils.info("PathActivity1",getDataDir().getAbsolutePath());
                    LogUtils.info("PathActivity2",getDatabaseDir().getAbsolutePath());
                    LogUtils.info("PathActivity3",getFilesDir().getAbsolutePath());
                    LogUtils.info("PathActivity4",getPreferencesDir().getAbsolutePath());
                    LogUtils.info("PathActivity5", getApplicationInfo().getEntryDir());
                    LogUtils.info("PathActivity6", getBundleCodePath());
                    LogUtils.info("PathActivity7", getBundleResourcePath());
                    LogUtils.info("PathActivity8", getCodeCacheDir().getAbsolutePath());
                    break;

                //应用外部存储路径
                case 1:
                    new ToastDialog(getContext()).setText("已输出到HiLog上").show();
                    LogUtils.info("PathActivity01：",getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath());
                    LogUtils.info("PathActivity02：",getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
                    LogUtils.info("PathActivity03：",getExternalFilesDir(Environment.DIRECTORY_MUSIC).getAbsolutePath());
                    LogUtils.info("PathActivity04：",getExternalFilesDir(Environment.DIRECTORY_MOVIES).getAbsolutePath());
                    LogUtils.info("PathActivity05：",getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath());
                    break;

                //外部存储路径（SDCcard）
                case 2:
                    new ToastDialog(getContext()).setText("信息已输出到HiLog上").show();
                    LogUtils.info("PathActivity01：",getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath());
                    LogUtils.info("PathActivity02：",getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
                    LogUtils.info("PathActivity03：",getExternalFilesDir(Environment.DIRECTORY_MUSIC).getAbsolutePath());
                    LogUtils.info("PathActivity04：",getExternalFilesDir(Environment.DIRECTORY_MOVIES).getAbsolutePath());
                    LogUtils.info("PathActivity05：",getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath());
                    break;
            }

        });
    }

    private List<MyListBean> initData() {
        List<MyListBean> lists = new ArrayList<>();
        lists.add(new MyListBean("内部存储路径"));
        lists.add(new MyListBean("应用外部存储路径"));
        lists.add(new MyListBean("外部存储路径（SDCard）"));
        return lists;
    }


}
